/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.opensagres.xdocreport.samples.odtandfreemarker.model;

import java.io.BufferedOutputStream;
import java.io.File;

/**
 *
 * @author magzupao
 */
public class ProjectImage {

    private File logoFile;
    private String urlFoto;

    public File getLogoFile() {
        return recuperaImagen();
    }

    public String getUrlFoto() {
        return urlFoto;
    }

    public void setUrlFoto(String urlFoto) {
        this.urlFoto = urlFoto;
    }

    public File recuperaImagen() {

        File archivo = new File("magzpicture.jpg");
        try {
            java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(getUrlFoto()).openStream());
            java.io.FileOutputStream fos = new java.io.FileOutputStream(archivo);
            java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
            byte data[] = new byte[1024];
            while (in.read(data, 0, 1024) >= 0) {
                bout.write(data);
            }
            bout.close();
            in.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return archivo;
    }
}
